// default package
// Generated Jul 28, 2012 3:15:14 PM by Hibernate Tools 3.4.0.CR1
package cl.usm.taller.corona.dao;

import java.util.List;
import javax.naming.InitialContext;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.HibernateException;
import org.hibernate.LockMode;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.classic.Session;
import org.hibernate.criterion.Example;

import cl.usm.taller.corona.model.EstadosEvaluacion;
import cl.usm.taller.corona.model.Usuario;
import cl.usm.taller.corona.util.HibernateUtil;

/**
 * Home object for domain model class EstadosEvaluacion.
 * @see .EstadosEvaluacion
 * @author Hibernate Tools
 */
public class EstadosEvaluacionDao {

	private static final Log log = LogFactory
			.getLog(EstadosEvaluacionDao.class);

	public void persist(EstadosEvaluacion transientInstance) {
		log.debug("persisting EstadosEvaluacion instance");
		Transaction transaction = null;
		
		try {
			Session session=HibernateUtil.getSessionFactory().getCurrentSession();
			transaction= session.beginTransaction();
			session.persist(transientInstance);
			transaction.commit();
			log.debug("persist successful");
		} catch (RuntimeException re) {
			log.error("persist failed", re);
			transaction.rollback();
			throw re;
		}
		finally
		{
			transaction=null;
		}
	}
	
	public void delete(EstadosEvaluacion persistentInstance) {
		log.debug("deleting EstadosEvaluacion instance");
		Transaction transaction = null;
		try {
			Session session=HibernateUtil.getSessionFactory().getCurrentSession();
			transaction= session.beginTransaction();
			session.delete(persistentInstance);
			transaction.commit();
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			transaction.rollback();
			throw re;
		}
		finally
		{
			transaction=null;
		}
	}
	
	
	public EstadosEvaluacion merge(EstadosEvaluacion detachedInstance) {
		log.debug("merging EstadosEvaluacion instance");
		try {
			Session session = HibernateUtil.getSessionFactory().getCurrentSession();
			session.beginTransaction();
			EstadosEvaluacion result = (EstadosEvaluacion) session.merge(detachedInstance);
			session.getTransaction().commit();
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}
	
	public EstadosEvaluacion findById(java.lang.Integer id) {
		log.debug("getting Usuario instance with id: " + id);
		try {
			Session session = HibernateUtil.getSessionFactory().getCurrentSession();
			session.beginTransaction();
			EstadosEvaluacion instance = (EstadosEvaluacion) session.get("EstadosEvaluacion", id);
			session.getTransaction().commit();
			if (instance == null) {
				log.debug("get successful, no instance found");
			} else {
				log.debug("get successful, instance found");
			}
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}
	
	
	public List<EstadosEvaluacion> list() {
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
        List<EstadosEvaluacion> estados = null;
        try {
             
        	estados = (List<EstadosEvaluacion>)session.createQuery("from EstadosEvaluacion").list();
             
        } catch (HibernateException e) {
            e.printStackTrace();
            session.getTransaction().rollback();
        }
        session.getTransaction().commit();
        return estados;
    }
}
